using Avanzis.QueryFramework;
using NUnit.Framework;

namespace Avanzis.QueryBuilder.NUnit.MySql
{
    [TestFixture]
    public class MySqlSelectClauseTest : SelectClauseTest
    {
        private Dialects previousDialect = Dialects.MSSql2005Dialect;

        [TestFixtureSetUp]
        public void Setup()
        {
            previousDialect = QueryFrameworkConfiguration.Dialect;
            QueryFrameworkConfiguration.Dialect = Dialects.MySql;
            QueryBuilder.QueryProcessor.ResetProcessor();
        }

        [TestFixtureTearDown]
        public void TearDown()
        {
            QueryFrameworkConfiguration.Dialect = previousDialect;
        }

        /// <summary>
        /// Selects the top distinct.
        /// </summary>
        [Test]
        public override void SelectTopDistinct()
        {
            SelectClause select = new SelectClause();
            select.Fields.Add("CustomerId");
            select.SelectionType = SelectionTypes.Distinct;
            select.Limit = 10;
            Assert.AreEqual("SELECT DISTINCT CustomerId", select.ToString());
        }        

        [Test]
        public override void SelectTop()
        {
            SelectClause select = new SelectClause();
            select.Fields.Add("CustomerId");
            select.Limit = 10;
            Assert.AreEqual(10, select.Limit);
            Assert.AreEqual("SELECT CustomerId", select.ToString());
        }

        [Test]        
        public override void SelectEnableCalculateFoundRows()
        {
            SelectClause select = new SelectClause();
            select.Fields.Add("CustomerId");
            select.EnableCalculateFoundRows = true;

            Assert.AreEqual(true, select.EnableCalculateFoundRows);
            Assert.AreEqual("SELECT SQL_CALC_FOUND_ROWS CustomerId", select.ToString());
        }
       

      
    }
}
